#include<iostream>
#include<set>
#include<cstring>

using namespace std;

int map[20][20];
int dir[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
int ans;

void dfs(int qizi, int n, int m)
{
	ans = min(ans, qizi);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (map[i][j])
			{
				if (i >= 3 && map[i][j] == 1 && map[i - 1][j] == 1 && map[i - 2][j] == 0)
				{
					//up
					map[i][j] = 0;
					map[i - 2][j] = 1;
					map[i - 1][j] = 0;
					dfs(qizi - 1, n, m);
					map[i][j] = 1;
					map[i - 2][j] = 0;
					map[i - 1][j] = 1;
				}
				if (i <= n - 2 && map[i][j] == 1 && map[i + 1][j] == 1 && map[i + 2][j] == 0)
				{
					//down
					map[i][j] = 0;
					map[i + 2][j] = 1;
					map[i + 1][j] = 0;
					dfs(qizi - 1, n, m);
					map[i][j] = 1;
					map[i + 1][j] = 1;
					map[i + 2][j] = 0;
				}
				if (j >= 3 && map[i][j] == 1 && map[i][j - 1] == 1 && map[i][j - 2] == 0)
				{
					//left
					map[i][j] = 0;
					map[i][j - 2] = 1;
					map[i][j - 1] = 0;
					dfs(qizi - 1, n, m);
					map[i][j] = 1;
					map[i][j - 1] = 1;
					map[i][j - 2] = 0;
				}
				if (j <= m - 2 && map[i][j] == 1 && map[i][j + 1] == 1 && map[i][j + 2] == 0)
				{
					//right
					map[i][j] = 0;
					map[i][j + 2] = 1;
					map[i][j + 1] = 0;
					dfs(qizi - 1, n, m);
					map[i][j] = 1;
					map[i][j + 1] = 1;
					map[i][j + 2] = 0;
				}
			}
		}
	}
}


int main()
{
	int T, n, m, k;
	cin >> T;
	for (int j = 0; j < T; j++)
	{
		cin >> n >> m >> k;
		memset(map, 0, sizeof(map));
		ans = 6;
		for (int i = 0; i < k; i++)
		{
			int x, y;
			cin >> x >> y;
			map[x][y] = 1;
		}
		dfs(k, n, m);
		cout << ans << endl;
	}
	return  0;
}